home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / PRNDLL.ZIP / README.TXT < prev   
Encoding:
Text File  |  1996-12-21  |  8.3 KB  |  203 lines

  1.                    Introducing PrintDLL.DLL
  2.  
  3.      PrintDIB.DLL and this document Copyright (c) 1996 ASL
  4.                       All Rights Reserved
  5.  
  6. While working on a Delphi program we ran across a Canon printer driver 
  7. that was troublesome. It wouldn't allow us to use the standard Delphi 
  8. StretchDraw. Why? Well, it appears that StretchDraw is a wrapper for 
  9. StrecthBlt(), and an increasing number of printer drivers (including 
  10. the new Canon driver we tested with) won't support StretchBlt() 
  11. although they will work OK with StretchDIBits. 
  12.  
  13. Moreover, we had an older VB product that was also having the same 
  14. problem (it used StretchBlt() as well) on the new printer drivers, 
  15. so we decided that the best solution was to write a DLL that would 
  16. allow VB _and_ Delphi the same functionality. We used Borland's C++ 
  17. (V 3.1) to create the DLL with, so this will work on Windows, 
  18. Windows for Workgroups, and Windows95. (It's 16 bit.)
  19.  
  20. Working with DIBs and BITMAPINFOHEADER and all that stuff is, well, 
  21. confusing to a lot of us. The worst part is that the only place in the 
  22. typical app that the DIB code is needed for stretching is the printer, 
  23. so you wind up with a lot of code lying around that doesn't get used 
  24. very much. (We have yet to see a video driver that wouldn't work with
  25. StretchBlt.)
  26.  
  27. What PrintDLL does is take your bitmap information, turn it into a DIB, 
  28. and then outputs the DIB to the printer. Printer drivers that choke on 
  29. Delphi's StretchDraw are now able to accept your stretched bitmaps, and 
  30. you don't have to write volumes of DIB handling code just to stretch a 
  31. standard bitmap out to your printer. 
  32.  
  33. PrintDLL is suitable for doing labels, desktop publishing, paint programs, 
  34. or any other program that needs to output a bitmap on the printer in a 
  35. specific area and at a specific size. The Delphi 1.0 example code below 
  36. works OK and as you can see, it isn't exactly huge. Nor is the VB3 example 
  37. that is enclosed inside this ZIP.
  38.  
  39. Caveats: As far as we know this won't work on network drives. Your mileage 
  40. may vary. If it does, well, great. :-)
  41.  
  42. Can you do what PrintDLL does yourself? Of course you can. However, you 
  43. need to factor how long it would take you to do this vs. what it costs 
  44. to buy PrintDLL, which you basically plug in. PrintDLL costs far less than 
  45. one hour of your time, and it can be used in any project written with any 
  46. language that can call a DLL.
  47.  
  48. PrintDLL is shareware. That means you get to play with it as needed to see 
  49. if you want to use it in your application. If you do, you'll need to buy it. 
  50. To purchase PrintDLL, call 1-800-242-4775 and order PrintDLL as product 
  51. number 15031. Alternately (outside the USA) you can call +1-713-524-6394 or
  52. fax +1-713-524-6398 or send email with your card info to 
  53. 71355.470@compuserve.com (alternately you can access order services via the
  54. PsL web site at www.pslweb.com.) Please let them know what your email address
  55. is! When you order it, please also send an email to us. When we receive the
  56. notification via email from PsL, we send the non-shareware version (i.e. the
  57. shareware version doesn't put up the message box) to your email address.
  58.  
  59. PrintDLL is $16 US, and the preferred form of sending it is to your email 
  60. address. (It's a small ZIP file.) If you prefer to send a check or a company
  61. Purchase Order, mail it to:
  62.  
  63. ASL
  64. P.O. Box 581
  65. Ruidoso NM 88345
  66. email asl@itctel.com
  67.  
  68. Please specify PRINTDLL as part #15031 on your P.O. If you want it to come
  69. via snail mail on a disk, please specify this.
  70.  
  71. Restrictions: ASL makes no claim for fitness of purpose and makes no warranty 
  72. of any kind. You may not license out PrintDLL to others as a DLL, although 
  73. you can use it in your applications, commercial or otherwise. 
  74.  
  75. ****************************************************************************
  76.  
  77.  
  78. DELPHI EXAMPLE OF USING PRINTDLL:
  79.  
  80. { put this right after IMPLEMENTATION in the module you will use }
  81.  
  82. procedure stretchedoutput(phwnd: HWND; printDC: HDC;
  83.           hbmp: HBITMAP; hpal: HPalette;
  84.           Xpos: Integer; Ypos: Integer;
  85.           swidth: Integer;  sheight: integer); far; external 'PRINTDIB';
  86. (*
  87.  
  88.    phwnd -- the Form.Handle of the Form that you are printing from.
  89.             [ this is not required in the non-shareware version ]
  90.    printDC -- the printer DC
  91.    hbmp -- your bitmap handle to convert to a dib
  92.    hpal -- the color palette to use; PRINTDLL works with 256 colors too
  93.    xpos and ypos -- the upper left coordinate on the page of where the 
  94.                     bitmap is going
  95.    swidth and sheight -- the size in printer pixels of the printed bitmap
  96.  
  97. )*
  98.  
  99.  
  100. { This procedure assumes that you have a TBitmap named mybitmap.
  101.   Note that the HWND parameter used in the stretchedoutput() call 
  102.   assumes Form1.Handle. You will need to change these as needed for 
  103.   your application. }
  104.  
  105. procedure TestPrintDLL;
  106. var
  107.      hmemdc,
  108.      prdc:                   THandle;
  109.      cprn: array[0..63] of   Char;
  110.      cdev: array[0..63] of   Char;
  111.      cdrv: array[0..63] of   Char;
  112.      cop: array[0..63] of    Char;
  113.      achar:                  Char;
  114.      index, drvindex, j,
  115.      i, tst:                 Integer;
  116.      prnbitmap:              HBITMAP;
  117.      mypalette:              HPalette;
  118. begin
  119.      {************************************************************}
  120.      {                        STEP 1                              }
  121.      {    PARSE THE WIN.INI SETTING TO GET THE PRINTER DRIVER     }
  122.      {    AND CREATE A DC TO USE.                                 }
  123.      {************************************************************}
  124.      for i := 0 to 63 do begin
  125.          cprn[i] := chr(0);
  126.          cdev[i] := chr(0);   { no memset() in Delphi. Do this the }
  127.          cdrv[i] := chr(0);   { hard way... :-( }
  128.          cop[i] := chr(0);
  129.      end;
  130.      { Get the "device=" string in win.ini. This is where the info
  131.        regarding the printer setup lives. }
  132.      GetProfileString('Windows','device','',cprn,64);
  133.      { now parse the resulting string }
  134.      index := 0;
  135.      repeat
  136.        achar := cprn[index];
  137.        if(achar <> ',') then begin
  138.           cdev[index] := achar;
  139.           inc(index);
  140.        end;
  141.      until achar = ',';
  142.      inc(index);
  143.      drvindex := 0;
  144.      repeat
  145.        achar := cprn[index];
  146.        if(achar <> ',') then begin
  147.           cdrv[drvindex] := achar;
  148.           inc(drvindex);
  149.           inc(index);
  150.        end;
  151.      until achar = ',';
  152.      inc(index);
  153.      drvindex := 0;
  154.      repeat
  155.        achar := cprn[index];
  156.        if(achar <> chr(0)) then begin
  157.           cop[drvindex] := achar;
  158.           inc(drvindex);
  159.           inc(index);
  160.        end;
  161.      until achar = chr(0);
  162.      { Try to create a printer DC based on this info. }
  163.      prdc := CreateDC(cdrv,cdev,cop,NIL);
  164.      { Die if no printer DC -- but warn user first.  }
  165.      if(prdc < 1) then begin
  166.         messagedlg('Cannot create a printer DC.',
  167.                     mtwarning, [mbok], 0);
  168.         exit;
  169.      end;
  170.  
  171.      {************************************************************}
  172.      {                        STEP 2                              }
  173.      {       USE CreateCompatibleDC TO OBTAIN AN HBITMAP          }
  174.      {************************************************************}
  175.  
  176.      { create a memory DC }
  177.      hmemdc := CreateCompatibleDC(mybitmap.canvas.handle);
  178.      { create a bitmap ... prnbitmap := HBitmap }
  179.      prnbitmap := CreateCompatibleBitmap(mybitmap.canvas.handle,
  180.                                          mybitmap.width,
  181.                                          mybitmap.height);
  182.      { make sure to copy the palette over }
  183.      mypalette := mybitmap.canvas.palette;
  184.      SelectObject(hmemdc, prnbitmap);
  185.      SelectPalette(hmemdc, mypalette, TRUE);
  186.      { get the bitmap into the memory DC }
  187.      BitBlt(hmemdc, 0, 0, mybitmap.width, mybitmap.height,
  188.             mybitmap.canvas.handle, 0, 0, SRCCOPY);
  189.      { The string 'TESTPRINT' is the document name, and it's 9 chars long.  }
  190.      tst := Escape(prdc,STARTDOC,9,'TESTPRINT',NIL); 
  191.  
  192.      { ********************* CALL THE DLL **********************}
  193.      stretchedoutput(form1.handle, prdc, prnbitmap, mypalette, 0, 0, 1000, 500);
  194.  
  195.      { tell the printer to print }
  196.      Escape(prdc,NEWFRAME,0,NIL,NIL);
  197.      Escape(prdc,ENDDOC,0,NIL,NIL);
  198.      { clean up }  
  199.      DeleteDC(hmemdc);
  200.      DeleteObject(prnbitmap);
  201.      DeleteDC(prdc);
  202. end;
  203.